/*
 * @文件描述: 
 * @版本: 
 * @作者: 周晨阳
 * @Date: 2021-08-17 10:01:13
 */
#include "sigGenerator.h"
#ifdef WIN_SIM
/*
 * @文件描述: 自带的简易信号发生器，使用硬件DAC或者PWM产生波形
 * @版本: 
 * @作者: 周晨阳
 * @Date: 2021-01-26 23:19:21
 */
#include "sigGenerator.h"
#include "DAC.h"

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/
//比例系数
#define _K (4096.0f / DAC_REF_VOLTAGE)
/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/
static uint8_t currentWaveType;
static uint8_t State;
static uint16_t Duty;
static uint16_t Frequency;
/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/

/* Public functions ---------------------------------------------------------*/

void SigGenerator_Init(u16 arr, u16 psc)
{
    // TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
    // NVIC_InitTypeDef NVIC_InitStructure;
    // GPIO_InitTypeDef GPIO_InitStructure;

    // RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);  ///使能TIM3时钟
    // RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //使能GPIOA时钟
    // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
    // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //模拟输入
    // GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;  //下拉
    // GPIO_Init(GPIOA, &GPIO_InitStructure);        //初始化

    // TIM_TimeBaseInitStructure.TIM_Period = arr;                     //自动重装载值
    // TIM_TimeBaseInitStructure.TIM_Prescaler = psc;                  //定时器分频
    // TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数模式
    // TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;

    // TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStructure); //初始化TIM3

    // TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE); //允许定时器3更新中断
    // TIM_Cmd(TIM3, ENABLE);                     //使能定时器3
    // PAout(5) = 0;

    // NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;              //定时器3中断
    // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级1
    // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;        //子优先级3
    // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    // NVIC_Init(&NVIC_InitStructure);

    // GPIO_InitTypeDef GPIO_InitStructure;
    // TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
    // TIM_OCInitTypeDef TIM_OCInitStructure;

    // RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE); //TIM14时钟使能
    // RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE); //使能PORTF时钟

    // GPIO_PinAFConfig(GPIOF, GPIO_PinSource9, GPIO_AF_TIM14); //GPIOF9复用为定时器14

    // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;          //GPIOF9
    // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;       //复用功能
    // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //速度100MHz
    // GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;     //推挽复用输出
    // GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;       //上拉
    // GPIO_Init(GPIOF, &GPIO_InitStructure);             //初始化PF9

    // TIM_TimeBaseStructure.TIM_Prescaler = psc;                  //定时器分频
    // TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数模式
    // TIM_TimeBaseStructure.TIM_Period = arr;                     //自动重装载值
    // TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

    // TIM_TimeBaseInit(TIM14, &TIM_TimeBaseStructure); //初始化定时器14

    // //初始化TIM14 Channel1 PWM模式
    // TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;             //选择定时器模式:TIM脉冲宽度调制模式2
    // TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //比较输出使能
    // TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;      //输出极性:TIM输出比较极性低
    // TIM_OC1Init(TIM14, &TIM_OCInitStructure);                     //根据T指定的参数初始化外设TIM1 4OC1

    // TIM_OC1PreloadConfig(TIM14, TIM_OCPreload_Enable); //使能TIM14在CCR1上的预装载寄存器

    // TIM_ARRPreloadConfig(TIM14, ENABLE); //ARPE使能

    // TIM_Cmd(TIM14, ENABLE); //使能TIM14
}
void setWaveType(uint8_t type)
{
}
void triggerOn(void)
{
}
void triggerOff(void)
{
}
void setPWM_Duty(uint8_t duty)
{
}
void setWaveFrequency(uint16_t frequency)
{
}
void setWaveAmp(float amp)
{
}
void setWaveOffset(float offset)
{
}
//定时器3中断服务函数
void TIM3_IRQHandler(void)
{
    // if (TIM_GetITStatus(TIM3, TIM_IT_Update) == SET) //溢出中断
    // {
    //     //printf("trigger\n");
    //     PAout(5) = !PAout(5);
    // }
    // TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //清除中断标志位
}
#endif